<?php 
header('Content-Type: text/html; charset=utf-8');
/* mb_internal_encoding("UTF-8");
mb_regex_encoding("UTF-8"); */

/**
 * beimuaihui System
* Copyright(c) 2011-2020 beimuaihui.
* @license    http://www.gnu.org/licenses/gpl.html     This software Under GPL V3 License
* beimuaihui@gmail.com
* http://code.google.com/p/beimuaihui/
* $Id: index.php 430 2011-12-15 08:11:42Z beimuaihui@gmail.com $
*/
//echo '<pre>';print_r($_POST);print_r($_FILES);exit;
/**
 * empty data sql
 * truncate table member;
truncate table member_history;
truncate table member_point_change;
 */
error_reporting(E_ALL);
@ini_set("memory_limit", "1024M");
@ini_set("max_execution_time", "240");
@ini_set("short_open_tag", "Off");
@ini_set("magic_quotes_gpc", "Off");
@ini_set("magic_quotes_runtime", "Off");
@set_magic_quotes_runtime(0);

@ini_set('display_errors', 1);
date_default_timezone_set('Asia/Hong_Kong');

session_name(md5($_SERVER['HTTP_HOST']));
session_start();



include_once '../../config/config.php';

$aIncludePath = array(BAOGG_ROOT);
$aIncludePath[] = BAOGG_ROOT. 'library/';
$aIncludePath[] = BAOGG_ROOT . 'models/';
$aIncludePath[]= '.';

//echo '<pre>';print_r($aIncludePath);exit;
set_include_path(implode(PATH_SEPARATOR, $aIncludePath));


require_once 'Zend/Loader/Autoloader.php'; ////Zend_Loader::registerAutoload();

Zend_Loader::loadFile('smarty/Smarty.class.php');
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->pushAutoloader('Smarty', 'smartyAutoload');
$autoloader->setFallbackAutoloader(true);

//begin frimann2
include_once 'config.php';

$Member=new Member();
$MemberPointChange=new MemberPointChange();
$MemberHistory=new MemberHistory();

//$rs_member=$Member->getList(array('1=0'),array(),array('limit'=>1,'start'=>0));
$db=$Member->getAdapter();
$rs=$db->query("select * from stis_members")->fetchAll();
//echo __FILE__.__LINE__.'<pre>';print_r($rs);exit;
foreach((array)$rs as $v){
	//$kt=$v['F1'];
	$kt=trim($v['F1']);
	if(strlen($kt)<10){
		$kt = str_repeat('0',10- strlen($kt)) .$kt;
	}
	
	$name=$v['F2'];
	$time=$v['F3'];
	$point=0;
	
	$arr_time=array_filter(explode('-',$time),'is_numeric');
	
	if(!is_numeric($kt)){
		echo '<br />kt error'.$kt;
		continue;
	}
	if(count($arr_time)!=3){
		echo '<br />time error!'.$kt;
		//continue;		
	}else{
		$point=12*$arr_time[0]+$arr_time[1];
	}
	
	
	$rs_exist=$Member->getList(array('kt_id'=>$kt));
	if($rs_exist){
		echo '<br />exist list'.$kt;
		continue;
		/* $sql  = "INSERT INTO member_history (member_id,labor_union_id,user_name,kt_id,name,pass,email,phone,address,post_code,city,country,state,updated_time,is_active,joined_time,updated_by,work_phone,mobile,old_union,picture) 
		SELECT member_id,labor_union_id,user_name,kt_id,name,pass,email,phone,address,post_code,city,country,state,now(),is_active,joined_time,'import',work_phone,mobile,old_union,picture 
		FROM member WHERE kt_id NOT IN (SELECT kt FROM member_point_tmp) {$str_update}; ";
		$rs =$db->query($sql); */
	}
	
	
	$arr_insert=array('name'=>$name, 'user_name'=>$kt,'kt_id'=>$kt,'points'=>$point,'labor_union_id'=>68);
	$member_id=$Member->_insert($arr_insert);
	
	$rs_member=$Member->getOne($member_id);
	$arr_member_history=$rs_member[0];
	$arr_member_history['updated_time']=date("Y-m-d H:i:s");
	$arr_member_history['updated_by']='admin';
	$history_id=$MemberHistory->_insert($arr_member_history);
	
	
	if($point){
		$arr_point_change=array('member_id'=>$member_id);
		$arr_point_change['change_type']=$point>0?0:1;
		$arr_point_change['change_point']=abs($point);
		$arr_point_change['new_point']=$point;
		$arr_point_change['comments']='Add points by admin import';
		$arr_point_change['updated_time']=date('Y-m-d H:i:s');
		$arr_point_change['updated_by']='admin';
		$change_id=	$MemberPointChange->_insert($arr_point_change);
			
		
	}
	
}


